﻿using GalaSoft.MvvmLight.Messaging;
using SubVersionOne.Message;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Integration;

namespace SubVersionOne
{
    public partial class FormHost : Form
    {
        private ElementHost wpfHost;
        private WorkItemsView view;

        public string Message
        {
            get;
            private set;
        }
     
        public FormHost()
        {
            InitializeComponent();
            ViewModelLocator.MainStatic.OnClose -= MainStatic_OnClose;
            ViewModelLocator.MainStatic.OnClose += MainStatic_OnClose;
            this.wpfHost = new ElementHost();
            this.Load += FormHost_Load;

            this.Disposed += FormHost_Disposed;
          

        }

        void FormHost_Disposed(object sender, EventArgs e)
        {
            //ViewModelLocator.Cleanup();
         

        }
   

        void MainStatic_OnClose(object sender, string e)
        {
            //this.Invoke(new Action(() =>
            //{
                EventLogger.Info("Setting content {0}", e);
                this.Message =e;
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            //}));
        }

        void FormHost_Load(object sender, EventArgs e)
        {
            this.view= new WorkItemsView( );
            

            this.SuspendLayout();
            wpfHost.Visible = false;

            wpfHost.Dock = DockStyle.Fill;
            this.wpfHost.Child = view;

            EventLogger.Info("Adding Control to Host.");
            this.Controls.Add(wpfHost);

            this.ResumeLayout(true);
            wpfHost.Visible = true;
        }
    }
}
